package UILayer;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

/**
 * @author Alexander
 *
 */
public class TableProductTableModel extends AbstractTableModel {
	private ArrayList<PartOrderTableItem> data;
	
	public TableProductTableModel() {
		data = new ArrayList<PartOrderTableItem>();
	}
	
	@Override
	public boolean isCellEditable(int row, int column) {
		return false;
	}
	
	@Override
	public int getColumnCount() {
		return 6;
	}
	
	@Override
	public int getRowCount() {
		if(data == null){
			return 0;
		}
		else {
			return data.size();
		}
	}
	
	//I'm awesome
	
	@Override
	public String getColumnName(int column) {
		String columnName = "";
		switch (column) {
			case 0:
			columnName = "Vare nr.";
			break;
			
			case 1:
			columnName = "Beskrivelse";
			break;
			
			case 2:
			columnName = "Pris";
			break;
			
			case 3:
			columnName = "Antal";
			break;
			
			case 4:
			columnName = "Kolli";
			break;
			
			case 5:
			columnName = "Total";
			break;

		}
		return columnName;
	}
	
	@Override
	public Object getValueAt(int row, int column) {
		Object value = null;
		switch (column) {
			case 0:
			value = data.get(row).getItemID();
			break;
			
			case 1:
			value = data.get(row).getDescription();
			break;
			
			case 2:
			value = data.get(row).getPrice();
			break;
			
			case 3:
			value = data.get(row).getQuantity();
			break;
			
			case 4:
			value = data.get(row).getColli();
			break;
			
			case 5:
			value = data.get(row).getLineTotal();
			break;
			
		}
		return value;
	}
	
	public void addRow(PartOrderTableItem poti) {
		data.add(poti);
	}
		
}
